package com.shadow.cloud.security.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Slf4j
public final class BCryptPasswordUtils {

    private static final BCryptPasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder();

    BCryptPasswordUtils() {
    }

    /**
     * 加密
     */
    public static String encryptPassword(final String password) {
        return PASSWORD_ENCODER.encode(password);
    }

    /**
     * 解密
     */
    public static boolean decryptPassword(final String password, final String encodedPassword) {
        return PASSWORD_ENCODER.matches(password, encodedPassword);
    }

    public static void main(String[] args) {
        String resource = "1";
        String encode = encryptPassword(resource);
        log.info("resource : {}, target : {}", resource, encode);
        boolean isMatches = decryptPassword(resource, encode);
        log.info("isMatches : {}", isMatches);
    }
}
